package com.atguigui.leetcode;

import java.util.Arrays;

/**
 * 1051.高度检查器
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/6/13 10:01
 */
public class P1051HeightChecker {
    public static void main(String[] args) {
        Solution solution = new P1051HeightChecker().new Solution();
        // TO TEST
        int[] i = {1, 1, 4, 2, 1, 3};
        solution.heightChecker(i);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int heightChecker(int[] heights) {

            int result = 0;
            int[] h = Arrays.copyOf(heights, heights.length);
            Arrays.sort(heights);

            if (heights.toString().equals(h.toString())) {
                return 0;
            } else {
                for (int i = 0; i < heights.length; i++) {
                    if (heights[i] != h[i]) {
                        result++;
                    }
                }
            }

            return result;

        }
    }
}
